<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport"
			content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<script src="js/mui.js"></script>
		<script src="js/storage.js"></script>
		<link href="css/mui.css" rel="stylesheet" />
	</head>
	<body>
		<nav class="mui-bar mui-bar-tab">
			<a class="mui-tab-item mui-active" data="html/home.html">
				<span class="mui-icon mui-icon-home"></span>
				<span class="mui-tab-label">首页</span>
			</a>
			<a class="mui-tab-item" data="html/exhaust.html">
				<span class="mui-icon mui-icon-loop"></span>
				<span class="mui-tab-label">智能排风</span>
			</a>
			<a class="mui-tab-item" data="html/chat.html">
				<span class="mui-icon mui-icon-chatboxes"></span>
				<span class="mui-tab-label">AI</span>
			</a>
			<a class="mui-tab-item" data="html/report.html">
				<span class="mui-icon mui-icon-gear"></span>
				<span class="mui-tab-label">数据分析</span>
			</a>
			<a class="mui-tab-item" data="html/newMy.html">
				<span class="mui-icon mui-icon-person"></span>
				<span class="mui-tab-label">我的</span>
			</a>
		</nav>

		<script type="text/javascript">
			mui.init({
				//该属性禁用了当前页面的返回功能，但是还是有双击退出app的功能
				keyEventBind: {
					backbutton: false //关闭back按键监听
				}
			});
			var subpages = ['html/home.html','html/exhaust.html','html/chat.html','html/report.html', 'html/newMy.html'];
			var subPageStyle = {
				top: '0px',
				bottom: '50px',
			};

			function getinfo() {
				userCache.setOptions({
					loginUrl: 'html/login.html',
					success: data => {
						//获取当前窗体
						var self = plus.webview.currentWebview();

						for (var i = 0; i < subpages.length; i++) {
							//创建子窗体
							//参数顺序： 窗体内容对应html路径，窗体唯一名字id， 窗体样式， 给窗体传参
							var subview = plus.webview.create(subpages[i], subpages[i], subPageStyle,
								null);
							//子窗台隐藏
							subview.hide();
							//添加子窗体到当前窗体
							self.append(subview);
						}
						//设置默认显示的子窗体
						plus.webview.show('html/home.html');
					},
					error: (error, thrown) => {
						mui.openWindow({
							url: 'html/login.html',
							id: 'html/login.html',
							createNew: false,
							show: {
								autoShow: true,
							}
						});
						plus.webview.currentWebview().hide()
					},
				});
				userCache.getUserInfo();
			}

			//移动设备就绪
			mui.plusReady(function() {
				getinfo()
				//关闭等待框
				plus.nativeUI.closeWaiting();
				//显示当前页面
				mui.currentWebview.show();
			});

			//点击a，添加tap事件
			//通过选择器找到元素
			mui(".mui-bar-tab").on("tap", "a", function(e) {
				//切换子窗体
				//参数： 窗体id，切换效果，切换时间
				var subid = this.getAttribute("data");
				mui.fire(plus.webview.getWebviewById(subid), 'refresh')
				plus.webview.show(subid, "fade-in", 100);
				if (subid == 'html/newMy.html') {
					mui.fire(plus.webview.getWebviewById('html/home.html'), 'closeBLE')
				}
			})
		</script>

	</body>
</html>